using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gate : Prop
{
    public GameObject effect;
    bool open = false;

    protected override void Awake()
    {
        base.Awake();
        MessageManager.BindAction(MsgKey.OpenGate, OpenGate);
        effect.SetActive(false);
    }

    public void OpenGate()
    {
        open = true;
        effect.SetActive(true);
        //AudioSource audioSource =  GetComponent<AudioSource>();
        //if(audioSource.enabled) audioSource.Play();
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player" && open)
        {
            open = false;
            MessageManager.Run(MsgKey.Win);
            AudioSource audioSource = GetComponent<AudioSource>();
            audioSource.time = 0.1f;
            audioSource.pitch = 1.5f;
            if (audioSource.enabled) audioSource.Play();
        }
    }
}
